package com.lgl.scsapi.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class ApiWebMvcConfigurer implements WebMvcConfigurer {
    @Value("${wx.upload.path}")
    private String uploadPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        uploadPath = uploadPath.replaceAll("\\\\","/") + "/";
        //添加图片资源访问路径，addResourceHandler路径不要跟项目里现有目录路径名相同，
        //如staticFile，否则会导致staticFile目录文件无法正常访问
        registry.addResourceHandler("/apiImages/**").
                addResourceLocations("file:" + uploadPath);
    }
}